package com.slz.crm.server.controller;

import com.slz.crm.common.result.Result;
import com.slz.crm.pojo.entity.PermissionsEntity;
import com.slz.crm.pojo.vo.PermissionVO;
import com.slz.crm.server.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 权限
 */
@RequestMapping("/permission")
@RestController
@Slf4j
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    /**
     * 获取当前用户权限
     * @return
     */
    @RequestMapping("/getMyPermission")
    public Result<List<PermissionVO>> getMyPermission() {
        return Result.success(permissionService.getMyPermission());
    }

    /**
     * 获取所有权限
     * @return
     */
    @RequestMapping("/list")
    public Result<Map<String, List<PermissionVO>>> list() {
        Map<String, List<PermissionVO>> permissionMap = new HashMap<>();
        List<String> keys = permissionService.getKeyList();

        for (int i = 0; i < keys.size(); i++) {
            PermissionsEntity entity = new PermissionsEntity();
            entity.setId((long) i);
            List<PermissionVO> permissionVOList = permissionService.getPermissionList(entity);
            permissionMap.put(keys.get(i), permissionVOList);
        }

        return Result.success(permissionMap);
    }





}
